from pyecharts.charts import Line
import pyecharts.options as opts
from pyecharts.globals import ThemeType


def drawLine(obj, ts_code, start_date, end_date):
    return (
        # 创建一个折线图实例
        Line(init_opts=opts.InitOpts(width='1200px', theme=ThemeType.LIGHT))
        # 设置 x 轴数据
        .add_xaxis(obj.date_list)
        # 设置 y 轴数据
        .add_yaxis(series_name='每期持仓收益金额(元)'
                   , y_axis=obj.eveyProfit
                   , markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="min", name='最小值'),
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkLineItem(type_="average", name="平均值")
                ]), )
        # 设置全局属性
        .set_global_opts(
            title_opts=opts.TitleOpts(title=ts_code + '(时间：' + start_date + '至' + end_date + ')', subtitle=str(obj)),
            tooltip_opts=opts.TooltipOpts(trigger="axis"),
            toolbox_opts=opts.ToolboxOpts(is_show=True),
            xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
        )
        # 保存 html 页面
        # .render("templates/line_chart.html")
    )


def drawTwoLine(obj, obj2, ts_code, start_date, end_date):
    return (
        # 创建一个折线图实例
        Line(init_opts=opts.InitOpts(width='1200px', theme=ThemeType.LIGHT))
        # 设置 x 轴数据
        .add_xaxis(obj.date_list)
        # 设置 y 轴数据
        .add_yaxis(series_name='每期持仓收益金额(元)'
                   , y_axis=obj.eveyProfit
                   , markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="min", name='最小值'),
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkLineItem(type_="average", name="平均值")
                ]), )
        # 设置 y 轴数据
        .add_yaxis(series_name='沪深300每期持仓收益金额(元)'
                   , y_axis=obj2.eveyProfit
                   , markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="min", name='最小值'),
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkLineItem(type_="average", name="平均值")
                ]), )
        # 设置全局属性
        .set_global_opts(
            title_opts=opts.TitleOpts(title=ts_code + '(时间：' + start_date + '至' + end_date + ')', subtitle=str(obj)),
            tooltip_opts=opts.TooltipOpts(trigger="axis"),
            toolbox_opts=opts.ToolboxOpts(is_show=True),
            xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False),
        )
        # 保存 html 页面
        #.render("templates/line_chart.html")
    )
